﻿# -*- encoding: utf-8 -*- 
from itertools import groupby
from datetime import datetime, timedelta

from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import float_is_zero, float_compare, DEFAULT_SERVER_DATETIME_FORMAT
from odoo.tools.misc import formatLang

import odoo.addons.decimal_precision as dp

from odoo import http
from odoo.http import content_disposition, dispatch_rpc, request, \
    serialize_exception as _serialize_exception, Response


class fhdevice_fhdevice_info(models.Model):
    _name = 'fhdevice.fhdevice_info'
    _description = u'设备基础信息'
    _rec_name='fhdevicename'
    _order = 'id desc'    
	
    fhdevicename=fields.Char(u'设备名称',readonly=False,required=False,translate=False)
    fh_p_device=fields.Many2one('fhdevice.fhdevice_info',u'上级设备',readonly=False,required=False,translate=False)
    fhdevice_type=fields.Many2one('fhbase.fhdevice_type',u'设备类型',readonly=False,required=False,translate=False)    
    fh_no=fields.Char(u'设备编号',readonly=False,required=False,translate=False)    
    fhspecs=fields.Char(u'设备规格',readonly=False,required=False,translate=False)
    fhmodel=fields.Char(u'设备型号',readonly=False,required=False,translate=False)
    fhinput_date=fields.Date(u'投入使用日期',readonly=False,required=False,translate=False)
    fhwhether=fields.Boolean(u'是否固定资产',readonly=False,required=False,translate=False)
    fhasset_code=fields.Char(u'资产编码',readonly=False,required=False,translate=False)
    fhuser=fields.Many2one('hr.department',u'使用部门',readonly=False,required=False,translate=False)
    fhdevice_state=fields.Selection([('v1',u'运行'),('v2',u'报废')],u'设备状态',readonly=False,required=False,translate=False)
    fhcontact=fields.Char(u'厂家地址及联系方式',readonly=False,required=False,translate=False)
    #fhmanufacturer=fields.Char(u'制造厂商',readonly=False,required=False,translate=False)
    fhmanufacturer=fields.Many2one('res.partner',u'制造厂商',readonly=False,required=False,translate=False)    
    fhnumber=fields.Char(u'制造编号',readonly=False,required=False,translate=False)
    fhdate=fields.Date(u'制造日期',readonly=False,required=False,translate=False)
    fhpower=fields.Char(u'设备功率（KW）',readonly=False,required=False,translate=False)
    fhtime=fields.Char(u'使用时间（h)',readonly=False,required=False,translate=False)
    fhreserve1=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve2=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve3=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve4=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve5=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve6=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve7=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve8=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve9=fields.Char(u'预留',readonly=False,required=False,translate=False)
    fhreserve10=fields.Char(u'预留',readonly=False,required=False,translate=False)
    
    fhtestthml = fields.Char(string=u'显示字段2',readonly=False,)    
    
    def action_property_file_report(self):    
        request.session.res_model=self._name
        request.session.res_id=self.id  
        return {
                'name':"附件上传",
                'url':"/myattachment/static/index.html",
                'type': 'ir.actions.act_url',
                'target': 'self'                      
               }
               
    @api.multi
    def attachment_image_preview(self):
        """附件上传 第二种方式"""
        self.ensure_one()
        model_data =self.env['ir.model.data'].sudo()      
        view_document_file_kanban = model_data.get_object_reference('mail','view_document_file_kanban')        
        view_attachment_tree = model_data.get_object_reference('base','view_attachment_tree')
        view_attachment_form = model_data.get_object_reference('base','view_attachment_form')    
        domain = [('res_model', '=', self._name), ('res_id', '=', self.id)]
        return {
        'domain': domain,
        'res_model': 'ir.attachment',
        'name': u'附件管理',
        'type': 'ir.actions.act_window',
        'view_id': False,
        'view_mode': 'kanban,tree,form',
        'view_type': 'form',
        'views': [ 
        (view_document_file_kanban and view_document_file_kanban[1] or False, 'kanban'),
        (view_attachment_tree and view_attachment_tree[1] or False, 'tree'),
        (view_attachment_form and view_attachment_form[1] or False, 'form')     
        ],         
        'limit': 20,
        'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id)
        }             				   
    @api.multi
    def name_get(self):
        if 1==1:
            res = []
            for record in self.search([]):
                name = ""
                if 1==1:
                    name = '%s[%s]' % (record.fhdevicename,record.fh_no)
                res.append((record.id, name))
            return res
        return super(fhdevice_fhdevice_info, self).name_get()

	
	
    @api.model		
    def create(self, vals):
        #vals["fhtestthml"]="3333"
        print('vals',vals)
        result = super(fhdevice_fhdevice_info, self).create(vals)	
        return result
    @api.multi		
    def write(self, values):
        #values["fhtestthml"]="555555"
        print('values',values)	    
        result = super(fhdevice_fhdevice_info, self).write(values)		
		
        return result
    @api.multi
    def unlink(self):
	
        return super(fhdevice_fhdevice_info, self).unlink()
    @api.multi
    def copy(self, default=None):
        return super(fhdevice_fhdevice_info, self).copy(default)
    @api.multi
    def search(self, args, offset=0, limit=None, order=None, conChar=None, count=False):
        domain =None		
        domain = [('state', '=', '0')]		
        return super(fhdevice_fhdevice_info, self).search(args, offset=offset, limit=limit, order=order, count=count)

		
fhdevice_fhdevice_info() #对象定义结束
